home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-16 | 6.9 KB | 214 lines | [TEXT/MPS ] |
- #----------------------------------------------------------------------------------------------------------------------------------------------------
- # Hexify
- # MPW Shell Script
- # Written by Gina Cherry • August 16, 1991
- # Copyright: © 1991 by Apple Computer, Inc., all rights reserved.
- #
- # Usage:
- # Hexify name… [-t textfile] [-d] [-p] [-r]
- #
- # Function:
- # This script takes all StuffIt files from a list of one or more directories and all their
- # subdirectories, and makes them into .hqx files.
- # If the -d option is specified, Hexify deletes the StuffIt files as it goes.
- # If the -p option is specified, Hexify prints progress information to standard output.
- # If the -t option is specified, Hexify prepends the specified text file to each .hqx file.
- # If the -r options is specified, Hexify removes all special characters from the .hqx file name,
- # replacing them with the '-' character. This is useful if the files are to be moved to a UNIX
- # platform.
- #
- # Note:
- # Directory names should have a ':' at the end.
- #----------------------------------------------------------------------------------------------------------------------------------------------------
-
- # Don't exit on error.
- Set Exit 0
-
- # Initialize option variables.
- Set P ""
- Set D ""
- Set R ""
-
- # Initialize file variables.
- Set dirList ""
- Set textFile ""
-
- # Loop through parameters.
- Loop
-
- # Break if no more parameters.
- Break If "{1}" == ""
-
- # If -d option is specified, want to delete StuffIt files.
- If "{1}" == '-d'
- # Make sure -d has not already been given as an option.
- If {D} == ""
- Set D 1
- # If it has, write error message and exit script.
- Else
- Echo "### "{0}": Option ∂"{1}∂" multiply defined."
- Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
- Exit 1
- End
-
- # If -p option is specified, want to write progress information to standard output.
- Else If "{1}" == '-p'
- # Make sure -p has not already been given as a parameter.
- If {P} == ""
- Set P 1
- # If is has, write error message and exit script.
- Else
- Echo "### "{0}": Option ∂"{1}∂" multiply defined."
- Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
- Exit 1
- End
-
- # If the -r option is specified, want to remove special characters from the .hqx file name.
- Else If "{1}" == '-r'
- # Make sure -r has not already been given as a parameter.
- If {R} == ""
- Set R 1
- # If is has, write error message and exit script.
- Else
- Echo "### "{0}": Option ∂"{1}∂" multiply defined."
- Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
- Exit 1
- End
-
- # If the -t option is specified, want to prepend a text file to the .hqx file.
- Else If "{1}" == '-t'
- # Make sure -t has not already been given as a parameter.
- If {textFile} == ""
- Set T 1
- # Get next parameter, which should be the name of a text file.
- Shift 1
- # If there is no next parameter, write error message and exit script.
- If "{1}" == ""
- Echo "### {0}: Option ∂"{1}∂" must be followed by a file name."
- Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
- Exit 1
- # Otherwise set textFile to the next parameter.
- Else
- Set textFile "{1}"
- End
- # If -t has already been given, write error message and exit script.
- Else
- Echo "### "{0}": Option ∂"{1}∂" multiply defined."
- Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
- Exit 1
- End
-
- # Check for bad options.
- Else If "{1}" =~ /∂-≈/ || "{1}" == '-'
- Echo "### {0}: Option ∂"{1}∂" is not an option"
- Echo "### Usage: Hexify name… [-t textfile] [-d] [-p]"
- Exit 1
-
- # Otherwise, assume the parameter is a file or directory name, and add to list.
- Else
- Set dirList "{dirList} '{1}'"
- End >> Dev:StdErr
-
- # Get next parameter.
- Shift 1
- End
-
- # If there are no files or directories in the list, write error message and exit script.
- If "{dirList}" == ""
- Echo "### {0}: Must specify a directory to hexify."
- Echo "### Usage: Hexify name… [-t textfile] [-d] [-p]"
- Exit 1
- End >> Dev:StdErr
-
- # Check if -t options was specified.
- If {T}
- # Open the text file to be prepended to the hexified files. Discard diagnostic output.
- Open -t "{textFile}" ≥ Dev:Null
- # If the Open command failed, write error message and exit script.
- If {status} != 0
- Echo "### {0}: {textFile} is not a valid file"
- Echo "### Usage: Hexify name… [-t textfile] [-d] [-p]"
- Exit 2
- End >> Dev:StdErr
- # Select the entire text file.
- Find •:∞ "{textFile}"
- # Copy text file to clipboard.
- Copy § "{textFile}"
- # Close the text file; don't save changes.
- Close -n "{textFile}"
- End
-
- # Save value of NewWindowRect to restore later.
- Set OldWindowRect "{NewWindowRect}"
-
- # Want the workspace window to be small.
- Set NewWindowRect 0,0,100,100
-
- # Open a temporary workspace.
- Open -n -t {0}.Temp
-
- # Restore value of NewWindowRect.
- Set NewWindowRect "{OldWindowRect}"
-
- # Loop through the list of files and directories.
- For dir in {dirList}
-
- If !"`Exists "{dir}"`"
- Echo "# {0}: Unable to get information on {dir}" >> Dev:StdErr
- Continue
- End
-
- # Set variable theFiles to a list of the full pathnames of all StuffIt files in dir and all subfolders
- # of dir. Discard diagnostic output. The Echo and Continue commands in parentheses will be
- # executed if and only if the Files command fails. In that case, print an error message and
- # continue with the next iteration of the loop.
- Set theFiles "`Files -r -s -t SIT! -f "{dir}"≥ Dev:Null`"
-
- # Loop through files in variable theFiles.
- For fName in {theFiles}
-
- # Create a new file name, ending in.hqx.
- # Write the current file name to the temporary file, overwriting existing text.
- Echo {fName} > {0}.Temp
- # Position cursor at the beginning of the temporary file.
- Find • {0}.Temp
- # Replace the string '.sit' appearing at the end of a line with the string '.hqx'.
- Replace /.sit∞/ ".hqx" {0}.Temp
- # Set the variable tempName to the new file name.
- Set tempName "`Catenate {0}.Temp`"
-
- # If the -r option was specified, remove special characters from the file name using the tool
- # FTPName.
- If "{R}"
- Set hqxName "`FTPName "{tempName}"`"
- Else
- Set hqxName "{tempName}"
- End
-
- # Convert file to hex using BinHex tool, sending output to a file with the new hqxName.
- BinHex "{fName}" "{hqxName}"
-
- # If -p option was specified write progress information to standard output.
- If {P}
- Echo "{fName} -> {hqxName}"
- End
-
- # If the -d option was specified, delete the StuffIt file that was just hexified.
- If {D}
- Delete -y "{fName}"
- End
-
- # If the -t option was specified, open the hexified file and prepend the contents of the
- # clipboard to it. Close and save changes.
- If {T}
- Open -t "{HqxName}"
- Paste • "{HqxName}"
- Close -y "{HqxName}"
- End
- End
- End
-
- # Close the temporary file; don't save changes
- Close -n {0}.Temp
-
-